package com.peakmain.homemodule.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.peakmain.baselibrary.recyclerview.adapter.CommonRecyclerAdapter;
import com.peakmain.baselibrary.recyclerview.adapter.ViewHolder;
import com.peakmain.homemodule.R;
import com.peakmain.wanandroid.netmodule.bean.home.HomeArticleBean;
import com.peakmain.wanandroid.netmodule.constant.Constant;
import com.peakmain.wanandroid.netmodule.webview.BrowserActivity;
import com.peakmain.wanandroid.netmodule.webview.SonicJavaScriptInterface;

import java.util.List;

/**
 * author: peakmain
 * createdata：2019/7/17
 * mail: 2726449200@qq.com
 * desiption:
 */
public class HomeArticleAdapter extends CommonRecyclerAdapter<HomeArticleBean.DatasBean> {
    public HomeArticleAdapter(Context context, List<HomeArticleBean.DatasBean> data) {
        super(context, data, R.layout.recycler_home_artic);
    }

    @Override
    public void convert(ViewHolder holder, final HomeArticleBean.DatasBean item) {
        holder.setText(R.id.tv_title, item.getTitle());
        holder.setText(R.id.tv_name, String.format(mContext.getResources().getString(R.string.autor), item.getAuthor()));
        holder.setText(R.id.tv_data, String.format(mContext.getResources().getString(R.string.time), item.getNiceDate()));
        if(item.getType()==1){
            holder.setViewVisibility(R.id.iv_top,View.VISIBLE);
        }
        holder.setText(R.id.tv_classification, String.format(mContext.getResources().getString(R.string.classification), item.getSuperChapterName(), item.getChapterName()));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url = item.getLink();
                Intent intent = new Intent(mContext, BrowserActivity.class);
                intent.putExtra(BrowserActivity.PARAM_URL, url);
                intent.putExtra(BrowserActivity.PARAM_MODE, Constant.MODE_DEFAULT);
                intent.putExtra(SonicJavaScriptInterface.PARAM_CLICK_TIME, System.currentTimeMillis());
                mContext.startActivity(intent);
            }
        });
    }
}
